<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/css/layui.css" />
    <link rel="stylesheet" href="/static/css/common.css" />
</head>
<body>
<form class="layui-form" action="" lay-filter="editform">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">原密码</label>
                <div class="layui-input-block">
                    <input type="password" name="oldpwd" lay-affix="eye" lay-verify="required|len" autocomplete="off" min="5" placeholder="请输入原密码" class="layui-input">
                </div>
            </div>
			<div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-block">
                    <input type="password" name="newpwd" lay-affix="eye" lay-verify="required|len" autocomplete="off" min="5" placeholder="请输入新密码" class="layui-input">
                </div>
            </div>

            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-lg layui-btn-warm" lay-submit="" lay-filter="txt-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
        </div>
    </div>
</form>
<script src="/static/js/layui.js"></script>
<script>
    layui.extend({
        api: '{/}/static/js/api' // 开头特定符 {/} 即代表采用单独路径
    });
    layui.use(['api'], function () {
        let form = layui.form
            , layer = layui.layer
            , api = layui.api
			, $ = layui.$;
        form.verify({
            len : (val, item) => {
                let min = item.getAttribute("min")
                if(val.length < min) {
                    return '长度不能小于' + min;
                }
            }
        })
        //监听提交
        form.on('submit(txt-save)', function (data) {
			data = data.field;
            if(data.oldpwd == data.newpwd) {
                layer.msg("密码一致，请修改新密码！", {icon:2});
                return false;
            }
			api.post('admin/changepwd', data, res => {
                layer.msg("修改成功", {icon:1})
				parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
			})

            return false;
        });

    });
</script>

</body>
</html>